package model.admin;

import java.sql.ResultSet;
import java.util.ArrayList;

import myutil.Connect;

import vo.DepartmentDetailsVo;
import vo.mixed.CourseListVo;
import vo.mixed.DegreeListVo;
import vo.mixed.DepartmentListVo;
import vo.mixed.ProfessorListVo;

public class GetListsMo {
	
	
public ArrayList<String> getCourseList(int batch_id, int professor_id, int student_id){
//	This method populates lists for adding course to a particular batch or professor or student
//	author: Ashwini 
	
	String query="";
	ArrayList<String> course_list = new ArrayList<String>();
	if(batch_id!=0)
		query="select c.course_name," +
    	" c.course_code," +
    	" c.course_id , " +
    	" dd.department_name, " +
    	" dd.department_id" +
   " from degree_department d, " +
   		" course_details c, " +
   		" department_details dd " +
   "where d.department_id	=	dd.department_id " +
   	 "and c.department_id	=	d.department_id " +
   	 "and d.batch_id		!=	"+batch_id+";";

	if(professor_id!=0)
		query="";
	if(student_id!=0)
		query="";
	System.out.println("\n Query is "+query);
	Connect c = new Connect();
	try {
		
		ResultSet rs=c.getResult(query);

			while(rs.next()){
//		CourseListVo single_object = new CourseListVo();
//	single_object.setCourse_code(rs.getString("c.course_code"));
//	single_object.setCourse_id(rs.getInt("c.course_id"));
//	single_object.setDepartment_id(rs.getInt("dd.department_id"));
			String single_object;
			single_object=rs.getString("c.course_name");
		course_list.add(single_object);
		
		}
	} catch (Exception e) {
	// TODO Auto-generated catch block
	e.printStackTrace();
	System.out.println(e.getMessage());
	}
		
		return course_list;
		}

//Get all the department of particular batch which are in active state
public ArrayList<DepartmentListVo> department_list(int batch_id) {
	String query = "";

	query = "select d.department_name" + "from degree_department dd, "
			+ "     department_details d "
			+ "where d.department_id		=		dd.department_id"
			+ "  and dd.batch_id			=		" + batch_id 
			+ "  and d.status				=		'Active';";
	ArrayList<DepartmentListVo> department_list = new ArrayList<DepartmentListVo>();
	Connect c = new Connect();

	try {
		ResultSet rs = c.getResult(query);
		while (rs.next()) {
			DepartmentListVo vo = new DepartmentListVo();
			vo.setDepartment_id(rs.getInt("department_id"));
			vo.setDepartment_name(rs.getString("department_name"));
			department_list.add(vo);
		}

	} catch (Exception e) {
		// TODO: handle exception
	}
	return department_list;
}

public ArrayList<Integer> GetYearList() {
	ArrayList<Integer> yearList = new ArrayList<Integer>();

	for (int i = 2000; i < 2020; i++) {
		yearList.add(i);
	}
	return yearList;
}

//Function to get all Degree List which are in Active State
public ArrayList<DegreeListVo> getDegreeList() {
	ArrayList<DegreeListVo> degree_list = new ArrayList<DegreeListVo>();
	String query = "";
	query = "select * from degree_details d where d.status='Active'";
	System.out.println(query);
	Connect c = new Connect();
	try {
		ResultSet rs = c.getResult(query);
		while (rs.next()) {
			DegreeListVo vo = new DegreeListVo();
			vo.setDegree_id(rs.getInt("degree_id"));
			vo.setBatch_name(rs.getString("degree_name"));
			degree_list.add(vo);
		}

	} catch (Exception e) {
		// TODO: handle exception
	}
	return degree_list;
}

//Function to get all incharge list which are in Active Statae
public ArrayList<String> getInchangeList() {
	ArrayList<String> incharge_list = new ArrayList<String>();
	String query = "select staff_id,staff_name from college_staff where status='Active';";
	Connect c = new Connect();
	try {
		ResultSet r = c.getResult(query);
		while (r.next()) {
			String single_object;
			single_object = r.getString("staff_name");
			System.out.println(single_object);
			incharge_list.add(single_object);
		}

	} catch (Exception e) {
		// TODO: handle exception
	}

	return incharge_list;
}

//Function to retrieve all the Departments that are in Active state
public ArrayList<DepartmentListVo> getDepartmentList() {
	ArrayList<DepartmentListVo> dept_list = new ArrayList<DepartmentListVo>();
	String query = "select * from department_details where status='Active';";
	Connect c = new Connect();
	try {
		ResultSet r = c.getResult(query);
		while (r.next()) {
			DepartmentListVo single_object = new DepartmentListVo();
			single_object.setDepartment_id(r.getInt("department_id"));
			single_object.setDepartment_name(r.getString("department_name"));
			System.out.println(single_object);
			dept_list.add(single_object);
		}

	} catch (Exception e) {
		// TODO: handle exception
	}
	return dept_list;
}

public ArrayList<String> getStudentList() {
	ArrayList<String> student_list = new ArrayList<String>();
	String query = "select * from student_details where student_id=(select student_id from student_batch where batch_id =0) and status=1;";
	Connect c = new Connect();
	try {
		ResultSet r = c.getResult(query);
		while (r.next()) {
			String single_object;
			single_object = r.getString("student_name");
			System.out.println(single_object);
			student_list.add(single_object);
		}
	} catch (Exception e) {
		// TODO: handle exception
	}
	return student_list;
}


//Function to get All the courses that are Active
public ArrayList<CourseListVo> getAllCourses()
	{
	ArrayList<CourseListVo> courselist= new ArrayList<CourseListVo>();
	String query="select * from course_details where status='Active'";
	Connect c = new Connect();
	try {
		ResultSet rs = c.getResult(query);
		while (rs.next()) {
			CourseListVo vo= new CourseListVo();
			vo.setCourse_id(rs.getInt("course_id"));
			vo.setCourse_name(rs.getString("course_name"));
			courselist.add(vo);
		}
	} catch (Exception e) {
		// TODO: handle exception
	}
	return courselist;
	}

}
